﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using System.Data.Common;
using System.Collections;

namespace DALL.Progect
{
    public class T_PUB_FILE
    {
        public T_PUB_FILE()
        { }

        /// <summary>
        /// 智能提示文件名称
        /// </summary>
        /// <param name="branch_id"></param>
        /// <returns></returns>
        public DataSet GetFileTitel(int branch_id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select DISTINCT FILE_TITEL FROM T_PUB_FILE ");
            strSql.Append(" where ISUSED=1 and BRANCH_ID=" + branch_id);
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        public DataSet GetFileTitel()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select DISTINCT FILE_TITEL FROM T_PUB_FILE where ISUSED=1 ");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        public void AddFileProject(Model.Progect.T_PUB_FILE FileModel, Model.Progect.T_PUB_FILEATTRIBUTE FileAttribute, IList<Model.Progect.T_PUB_PROJECTFILE> projectlist)
        {
            ArrayList strArry = new ArrayList();

            #region 修改文件
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_PUB_FILE set ");
            strSql.Append("REAMRK='" + FileModel.REAMRK + "',");
            if (FileModel.ISFLAG)
            {
                strSql.Append("ISFLAG= 1,");
            }
            else
            {
                strSql.Append("ISFLAG= 0,");
            }
            strSql.Append("FILE_FORM='" + FileModel.FILE_FORM + "',");
            strSql.Append("UPDATEUSERID='" + FileModel.UPDATEUSERID + "',");
            strSql.Append("UPDATEUSERNAME='" + FileModel.UPDATEUSERNAME + "',");
            strSql.Append("GETTIME='" + FileModel.GETTIME + "',");
            strSql.Append("SETTOPTIME='" + FileModel.SETTOPTIME + "',");
            strSql.Append("FILE_TITEL='" + FileModel.FILE_TITEL + "'");
            strSql.Append(" where FILE_ID='" + FileModel.FILE_ID + "' ");
            strArry.Add(strSql);
            #endregion

            #region 添加文件属性
            StringBuilder strSqls = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (FileAttribute.FILE_ID != null)
            {
                strSql1.Append("FILE_ID,");
                strSql2.Append("'" + FileAttribute.FILE_ID + "',");
            }
            if (FileAttribute.AREA != null)
            {
                strSql1.Append("AREA,");
                strSql2.Append("'" + FileAttribute.AREA + "',");
            }
            if (FileAttribute.CELEBRATION_TYPE != null)
            {
                strSql1.Append("CELEBRATION_TYPE,");
                strSql2.Append("'" + FileAttribute.CELEBRATION_TYPE + "',");
            }
            if (FileAttribute.NEWSCHOOL != null)
            {
                strSql1.Append("NEWSCHOOL,");
                strSql2.Append("'" + FileAttribute.NEWSCHOOL + "',");
            }
            if (FileAttribute.MYXILAI != null)
            {
                strSql1.Append("MYXILAI,");
                strSql2.Append("'" + FileAttribute.MYXILAI + "',");
            }
            if (FileAttribute.STYLE != null)
            {
                strSql1.Append("STYLE,");
                strSql2.Append("'" + FileAttribute.STYLE + "',");
            }
            if (FileAttribute.COLOR != null)
            {
                strSql1.Append("COLOR,");
                strSql2.Append("'" + FileAttribute.COLOR + "',");
            }
            if (FileAttribute.DRESS_TYPE != null)
            {
                strSql1.Append("DRESS_TYPE,");
                strSql2.Append("'" + FileAttribute.DRESS_TYPE + "',");
            }
            if (FileAttribute.DRESS_LEVEL != null)
            {
                strSql1.Append("DRESS_LEVEL,");
                strSql2.Append("'" + FileAttribute.DRESS_LEVEL + "',");
            }
            if (FileAttribute.DRESS_COLOR != null)
            {
                strSql1.Append("DRESS_COLOR,");
                strSql2.Append("'" + FileAttribute.DRESS_COLOR + "',");
            }
            if (FileAttribute.DRESS_PRICE != null)
            {
                strSql1.Append("DRESS_PRICE,");
                strSql2.Append("'" + FileAttribute.DRESS_PRICE + "',");
            }
            if (FileAttribute.WEDDING_COLOR != null)
            {
                strSql1.Append("WEDDING_COLOR,");
                strSql2.Append("'" + FileAttribute.WEDDING_COLOR + "',");
            }
            if (FileAttribute.WEDDING_PRICE != null)
            {
                strSql1.Append("WEDDING_PRICE,");
                strSql2.Append("'" + FileAttribute.WEDDING_PRICE + "',");
            }
            if (FileAttribute.WEDDING_MONTH != null)
            {
                strSql1.Append("WEDDING_MONTH,");
                strSql2.Append("'" + FileAttribute.WEDDING_MONTH + "',");
            }
            if (FileAttribute.WEDDING_STYLE != null)
            {
                strSql1.Append("WEDDING_STYLE,");
                strSql2.Append("'" + FileAttribute.WEDDING_STYLE + "',");
            }
            if (FileAttribute.MATERIAL_STAR != null)
            {
                strSql1.Append("MATERIAL_STAR,");
                strSql2.Append("'" + FileAttribute.MATERIAL_STAR + "',");
            }
            if (FileAttribute.HOTEL_NAME != null)
            {
                strSql1.Append("HOTEL_NAME,");
                strSql2.Append("'" + FileAttribute.HOTEL_NAME + "',");
            }
            if (FileAttribute.HOTEL_DESK_NUM != null)
            {
                strSql1.Append("HOTEL_DESK_NUM,");
                strSql2.Append("'" + FileAttribute.HOTEL_DESK_NUM + "',");
            }
            if (FileAttribute.HOTEL_STYLE != null)
            {
                strSql1.Append("HOTEL_STYLE,");
                strSql2.Append("'" + FileAttribute.HOTEL_STYLE + "',");
            }
            if (FileAttribute.HOTEL_SPECIFICATION != null)
            {
                strSql1.Append("HOTEL_SPECIFICATION,");
                strSql2.Append("'" + FileAttribute.HOTEL_SPECIFICATION + "',");
            }
            if (FileAttribute.HOTEL_LOCATION != null)
            {
                strSql1.Append("HOTEL_LOCATION,");
                strSql2.Append("'" + FileAttribute.HOTEL_LOCATION + "',");
            }
            if (FileAttribute.MAX_PRICE != null)
            {
                strSql1.Append("MAX_PRICE,");
                strSql2.Append("" + FileAttribute.MAX_PRICE + ",");
            }
            if (FileAttribute.MIN_PRICE != null)
            {
                strSql1.Append("MIN_PRICE,");
                strSql2.Append("" + FileAttribute.MIN_PRICE + ",");
            }
            if (FileAttribute.PROJECT_TYPE != null)
            {
                strSql1.Append("PROJECT_TYPE,");
                strSql2.Append("'" + FileAttribute.PROJECT_TYPE + "',");
            }
            strSqls.Append("insert into T_PUB_FILEATTRIBUTE(");
            strSqls.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSqls.Append(")");
            strSqls.Append(" values (");
            strSqls.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSqls.Append(")");
            strArry.Add(strSqls);
            #endregion

            #region 添加文件项目
            foreach (Model.Progect.T_PUB_PROJECTFILE item in projectlist)
            {
                StringBuilder strSqlp = new StringBuilder();
                StringBuilder strSqls1 = new StringBuilder();
                StringBuilder strSqls2 = new StringBuilder();
                if (item.PROJECT_ID != null)
                {
                    strSqls1.Append("PROJECT_ID,");
                    strSqls2.Append("'" + item.PROJECT_ID + "',");
                }
                if (item.FILE_ID != null)
                {
                    strSqls1.Append("FILE_ID,");
                    strSqls2.Append("'" + item.FILE_ID + "',");
                }
                strSqlp.Append("insert into T_PUB_PROJECTFILE(");
                strSqlp.Append(strSqls1.ToString().Remove(strSqls1.Length - 1));
                strSqlp.Append(")");
                strSqlp.Append(" values (");
                strSqlp.Append(strSqls2.ToString().Remove(strSqls2.Length - 1));
                strSqlp.Append(")");
                strSqlp.Append(";select @@IDENTITY");
                strArry.Add(strSqlp);
            }
            #endregion

            DBHelper.ExecuteSqlTran(strArry);
        }

        public void AddFileProject(Model.Progect.T_PUB_FILE FileModel, Model.Progect.T_PUB_FILEATTRIBUTE FileAttribute)
        {
            ArrayList strArry = new ArrayList();

            #region 修改文件
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_PUB_FILE set ");
            strSql.Append("REAMRK='" + FileModel.REAMRK + "',");
            if (FileModel.ISFLAG)
            {
                strSql.Append("ISFLAG= 1,");
            }
            else
            {
                strSql.Append("ISFLAG= 0,");
            }
            strSql.Append("FILE_FORM='" + FileModel.FILE_FORM + "',");
            strSql.Append("UPDATEUSERID='" + FileModel.UPDATEUSERID + "',");
            strSql.Append("UPDATEUSERNAME='" + FileModel.UPDATEUSERNAME + "',");
            strSql.Append("GETTIME='" + FileModel.GETTIME + "',");
            strSql.Append("SETTOPTIME='" + FileModel.SETTOPTIME + "',");
            strSql.Append("FILE_TITEL='" + FileModel.FILE_TITEL + "'");
            strSql.Append(" where FILE_ID='" + FileModel.FILE_ID + "' ");
            strArry.Add(strSql);
            #endregion

            #region 添加文件属性
            StringBuilder strSqls = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (FileAttribute.FILE_ID != null)
            {
                strSql1.Append("FILE_ID,");
                strSql2.Append("'" + FileAttribute.FILE_ID + "',");
            }
            if (FileAttribute.AREA != null)
            {
                strSql1.Append("AREA,");
                strSql2.Append("'" + FileAttribute.AREA + "',");
            }
            if (FileAttribute.CELEBRATION_TYPE != null)
            {
                strSql1.Append("CELEBRATION_TYPE,");
                strSql2.Append("'" + FileAttribute.CELEBRATION_TYPE + "',");
            }
            if (FileAttribute.NEWSCHOOL != null)
            {
                strSql1.Append("NEWSCHOOL,");
                strSql2.Append("'" + FileAttribute.NEWSCHOOL + "',");
            }
            if (FileAttribute.MYXILAI != null)
            {
                strSql1.Append("MYXILAI,");
                strSql2.Append("'" + FileAttribute.MYXILAI + "',");
            }
            if (FileAttribute.STYLE != null)
            {
                strSql1.Append("STYLE,");
                strSql2.Append("'" + FileAttribute.STYLE + "',");
            }
            if (FileAttribute.COLOR != null)
            {
                strSql1.Append("COLOR,");
                strSql2.Append("'" + FileAttribute.COLOR + "',");
            }
            if (FileAttribute.DRESS_TYPE != null)
            {
                strSql1.Append("DRESS_TYPE,");
                strSql2.Append("'" + FileAttribute.DRESS_TYPE + "',");
            }
            if (FileAttribute.DRESS_LEVEL != null)
            {
                strSql1.Append("DRESS_LEVEL,");
                strSql2.Append("'" + FileAttribute.DRESS_LEVEL + "',");
            }
            if (FileAttribute.DRESS_COLOR != null)
            {
                strSql1.Append("DRESS_COLOR,");
                strSql2.Append("'" + FileAttribute.DRESS_COLOR + "',");
            }
            if (FileAttribute.DRESS_PRICE != null)
            {
                strSql1.Append("DRESS_PRICE,");
                strSql2.Append("'" + FileAttribute.DRESS_PRICE + "',");
            }
            if (FileAttribute.WEDDING_COLOR != null)
            {
                strSql1.Append("WEDDING_COLOR,");
                strSql2.Append("'" + FileAttribute.WEDDING_COLOR + "',");
            }
            if (FileAttribute.WEDDING_PRICE != null)
            {
                strSql1.Append("WEDDING_PRICE,");
                strSql2.Append("'" + FileAttribute.WEDDING_PRICE + "',");
            }
            if (FileAttribute.WEDDING_MONTH != null)
            {
                strSql1.Append("WEDDING_MONTH,");
                strSql2.Append("'" + FileAttribute.WEDDING_MONTH + "',");
            }
            if (FileAttribute.WEDDING_STYLE != null)
            {
                strSql1.Append("WEDDING_STYLE,");
                strSql2.Append("'" + FileAttribute.WEDDING_STYLE + "',");
            }
            if (FileAttribute.MATERIAL_STAR != null)
            {
                strSql1.Append("MATERIAL_STAR,");
                strSql2.Append("'" + FileAttribute.MATERIAL_STAR + "',");
            }
            if (FileAttribute.HOTEL_NAME != null)
            {
                strSql1.Append("HOTEL_NAME,");
                strSql2.Append("'" + FileAttribute.HOTEL_NAME + "',");
            }
            if (FileAttribute.HOTEL_DESK_NUM != null)
            {
                strSql1.Append("HOTEL_DESK_NUM,");
                strSql2.Append("'" + FileAttribute.HOTEL_DESK_NUM + "',");
            }
            if (FileAttribute.HOTEL_STYLE != null)
            {
                strSql1.Append("HOTEL_STYLE,");
                strSql2.Append("'" + FileAttribute.HOTEL_STYLE + "',");
            }
            if (FileAttribute.HOTEL_SPECIFICATION != null)
            {
                strSql1.Append("HOTEL_SPECIFICATION,");
                strSql2.Append("'" + FileAttribute.HOTEL_SPECIFICATION + "',");
            }
            if (FileAttribute.HOTEL_LOCATION != null)
            {
                strSql1.Append("HOTEL_LOCATION,");
                strSql2.Append("'" + FileAttribute.HOTEL_LOCATION + "',");
            }
            if (FileAttribute.MAX_PRICE != null)
            {
                strSql1.Append("MAX_PRICE,");
                strSql2.Append("" + FileAttribute.MAX_PRICE + ",");
            }
            if (FileAttribute.MIN_PRICE != null)
            {
                strSql1.Append("MIN_PRICE,");
                strSql2.Append("" + FileAttribute.MIN_PRICE + ",");
            }
            if (FileAttribute.PROJECT_TYPE != null)
            {
                strSql1.Append("PROJECT_TYPE,");
                strSql2.Append("'" + FileAttribute.PROJECT_TYPE + "',");
            }
            strSqls.Append("insert into T_PUB_FILEATTRIBUTE(");
            strSqls.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSqls.Append(")");
            strSqls.Append(" values (");
            strSqls.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSqls.Append(")");
            strArry.Add(strSqls);
            #endregion

            DBHelper.ExecuteSqlTran(strArry);
        }

        public void EditFileProject(Model.Progect.T_PUB_FILE FileModel, Model.Progect.T_PUB_FILEATTRIBUTE FileAttribute, IList<Model.Progect.T_PUB_PROJECTFILE> addlist, IList<Model.Progect.T_PUB_PROJECTFILE> editlist)
        {
            ArrayList strArry = new ArrayList();

            #region 修改文件
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_PUB_FILE set ");
            strSql.Append("REAMRK='" + FileModel.REAMRK + "',");
            if (FileModel.ISFLAG)
            {
                strSql.Append("ISFLAG= 1,");
            }
            else
            {
                strSql.Append("ISFLAG= 0,");
            }
            strSql.Append("FILE_FORM='" + FileModel.FILE_FORM + "',");
            strSql.Append("UPDATEUSERID='" + FileModel.UPDATEUSERID + "',");
            strSql.Append("UPDATEUSERNAME='" + FileModel.UPDATEUSERNAME + "',");
            strSql.Append("GETTIME='" + FileModel.GETTIME + "',");
            strSql.Append("SETTOPTIME='" + FileModel.SETTOPTIME + "',");
            strSql.Append("FILE_TITEL='" + FileModel.FILE_TITEL + "'");
            strSql.Append(" where FILE_ID='" + FileModel.FILE_ID + "' ");
            strArry.Add(strSql);
            #endregion

            #region 修改文件属性
            StringBuilder strSqls = new StringBuilder();
            strSqls.Append("update T_PUB_FILEATTRIBUTE set ");
            if (FileAttribute.AREA != null)
            {
                strSqls.Append("AREA='" + FileAttribute.AREA + "',");
            }
            else
            {
                strSqls.Append("AREA= null ,");
            }
            if (FileAttribute.CELEBRATION_TYPE != null)
            {
                strSqls.Append("CELEBRATION_TYPE='" + FileAttribute.CELEBRATION_TYPE + "',");
            }
            else
            {
                strSqls.Append("CELEBRATION_TYPE= null ,");
            }
            if (FileAttribute.NEWSCHOOL != null)
            {
                strSqls.Append("NEWSCHOOL='" + FileAttribute.NEWSCHOOL + "',");
            }
            else
            {
                strSqls.Append("NEWSCHOOL= null ,");
            }
            if (FileAttribute.MYXILAI != null)
            {
                strSqls.Append("MYXILAI='" + FileAttribute.MYXILAI + "',");
            }
            else
            {
                strSqls.Append("MYXILAI= null ,");
            }
            if (FileAttribute.STYLE != null)
            {
                strSqls.Append("STYLE='" + FileAttribute.STYLE + "',");
            }
            else
            {
                strSqls.Append("STYLE= null ,");
            }
            if (FileAttribute.COLOR != null)
            {
                strSqls.Append("COLOR='" + FileAttribute.COLOR + "',");
            }
            else
            {
                strSqls.Append("COLOR= null ,");
            }
            if (FileAttribute.DRESS_TYPE != null)
            {
                strSqls.Append("DRESS_TYPE='" + FileAttribute.DRESS_TYPE + "',");
            }
            else
            {
                strSqls.Append("DRESS_TYPE= null ,");
            }
            if (FileAttribute.DRESS_LEVEL != null)
            {
                strSqls.Append("DRESS_LEVEL='" + FileAttribute.DRESS_LEVEL + "',");
            }
            else
            {
                strSqls.Append("DRESS_LEVEL= null ,");
            }
            if (FileAttribute.DRESS_COLOR != null)
            {
                strSqls.Append("DRESS_COLOR='" + FileAttribute.DRESS_COLOR + "',");
            }
            else
            {
                strSqls.Append("DRESS_COLOR= null ,");
            }
            if (FileAttribute.DRESS_PRICE != null)
            {
                strSqls.Append("DRESS_PRICE='" + FileAttribute.DRESS_PRICE + "',");
            }
            else
            {
                strSqls.Append("DRESS_PRICE= null ,");
            }
            if (FileAttribute.WEDDING_COLOR != null)
            {
                strSqls.Append("WEDDING_COLOR='" + FileAttribute.WEDDING_COLOR + "',");
            }
            else
            {
                strSqls.Append("WEDDING_COLOR= null ,");
            }
            if (FileAttribute.WEDDING_PRICE != null)
            {
                strSqls.Append("WEDDING_PRICE='" + FileAttribute.WEDDING_PRICE + "',");
            }
            else
            {
                strSqls.Append("WEDDING_PRICE= null ,");
            }
            if (FileAttribute.WEDDING_MONTH != null)
            {
                strSqls.Append("WEDDING_MONTH='" + FileAttribute.WEDDING_MONTH + "',");
            }
            else
            {
                strSqls.Append("WEDDING_MONTH= null ,");
            }
            if (FileAttribute.WEDDING_STYLE != null)
            {
                strSqls.Append("WEDDING_STYLE='" + FileAttribute.WEDDING_STYLE + "',");
            }
            else
            {
                strSqls.Append("WEDDING_STYLE= null ,");
            }
            if (FileAttribute.MATERIAL_STAR != null)
            {
                strSqls.Append("MATERIAL_STAR='" + FileAttribute.MATERIAL_STAR + "',");
            }
            else
            {
                strSqls.Append("MATERIAL_STAR= null ,");
            }
            if (FileAttribute.HOTEL_NAME != null)
            {
                strSqls.Append("HOTEL_NAME='" + FileAttribute.HOTEL_NAME + "',");
            }
            else
            {
                strSqls.Append("HOTEL_NAME= null ,");
            }
            if (FileAttribute.HOTEL_DESK_NUM != null)
            {
                strSqls.Append("HOTEL_DESK_NUM='" + FileAttribute.HOTEL_DESK_NUM + "',");
            }
            else
            {
                strSqls.Append("HOTEL_DESK_NUM= null ,");
            }
            if (FileAttribute.HOTEL_STYLE != null)
            {
                strSqls.Append("HOTEL_STYLE='" + FileAttribute.HOTEL_STYLE + "',");
            }
            else
            {
                strSqls.Append("HOTEL_STYLE= null ,");
            }
            if (FileAttribute.HOTEL_SPECIFICATION != null)
            {
                strSqls.Append("HOTEL_SPECIFICATION='" + FileAttribute.HOTEL_SPECIFICATION + "',");
            }
            else
            {
                strSqls.Append("HOTEL_SPECIFICATION= null ,");
            }
            if (FileAttribute.HOTEL_LOCATION != null)
            {
                strSqls.Append("HOTEL_LOCATION='" + FileAttribute.HOTEL_LOCATION + "',");
            }
            else
            {
                strSqls.Append("HOTEL_LOCATION= null ,");
            }
            if (FileAttribute.MAX_PRICE != null)
            {
                strSqls.Append("MAX_PRICE=" + FileAttribute.MAX_PRICE + ",");
            }
            else
            {
                strSqls.Append("MAX_PRICE= null ,");
            }
            if (FileAttribute.MIN_PRICE != null)
            {
                strSqls.Append("MIN_PRICE=" + FileAttribute.MIN_PRICE + ",");
            }
            else
            {
                strSqls.Append("MIN_PRICE= null ,");
            }
            if (FileAttribute.PROJECT_TYPE != null)
            {
                strSqls.Append("PROJECT_TYPE='" + FileAttribute.PROJECT_TYPE + "',");
            }
            else
            {
                strSqls.Append("PROJECT_TYPE= null ,");
            }
            int n = strSqls.ToString().LastIndexOf(",");
            strSqls.Remove(n, 1);
            strSqls.Append(" where FILE_ID='" + FileAttribute.FILE_ID + "' ");
            strArry.Add(strSqls);
            #endregion

            #region 添加文件项目
            foreach (Model.Progect.T_PUB_PROJECTFILE item in addlist)
            {
                StringBuilder strSqlp = new StringBuilder();
                StringBuilder strSqls1 = new StringBuilder();
                StringBuilder strSqls2 = new StringBuilder();
                if (item.PROJECT_ID != null)
                {
                    strSqls1.Append("PROJECT_ID,");
                    strSqls2.Append("'" + item.PROJECT_ID + "',");
                }
                if (item.FILE_ID != null)
                {
                    strSqls1.Append("FILE_ID,");
                    strSqls2.Append("'" + item.FILE_ID + "',");
                }
                strSqlp.Append("insert into T_PUB_PROJECTFILE(");
                strSqlp.Append(strSqls1.ToString().Remove(strSqls1.Length - 1));
                strSqlp.Append(")");
                strSqlp.Append(" values (");
                strSqlp.Append(strSqls2.ToString().Remove(strSqls2.Length - 1));
                strSqlp.Append(")");
                strSqlp.Append(";select @@IDENTITY");
                strArry.Add(strSqlp);
            }
            #endregion

            #region 修改文件项目
            foreach (Model.Progect.T_PUB_PROJECTFILE item in editlist)
            {
                StringBuilder strSqle = new StringBuilder();
                strSqle.Append("update T_PUB_PROJECTFILE set ");
                if (item.FILE_ID != null)
                {
                    strSqle.Append(" FILE_ID = '" + item.FILE_ID + "',");
                }
                else
                {
                    strSqle.Append(" FILE_ID = null ,");
                }
                if (item.PROJECT_ID != null)
                {
                    strSqle.Append(" PROJECT_ID = '" + item.PROJECT_ID + "',");
                }
                else
                {
                    strSqle.Append(" PROJECT_ID = null ,");
                }
                int h = strSqle.ToString().LastIndexOf(",");
                strSqle.Remove(h, 1);
                strSqle.Append(" where ID=" + item.ID + "");
            }
            #endregion

            DBHelper.ExecuteSqlTran(strArry);
        }

        public void EditFileProject(Model.Progect.T_PUB_FILE FileModel, Model.Progect.T_PUB_FILEATTRIBUTE FileAttribute)
        {
            ArrayList strArry = new ArrayList();

            #region 修改文件
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_PUB_FILE set ");
            strSql.Append("REAMRK='" + FileModel.REAMRK + "',");
            if (FileModel.ISFLAG)
            {
                strSql.Append("ISFLAG= 1,");
            }
            else
            {
                strSql.Append("ISFLAG= 0,");
            }
            strSql.Append("FILE_FORM='" + FileModel.FILE_FORM + "',");
            strSql.Append("UPDATEUSERID='" + FileModel.UPDATEUSERID + "',");
            strSql.Append("UPDATEUSERNAME='" + FileModel.UPDATEUSERNAME + "',");
            strSql.Append("GETTIME='" + FileModel.GETTIME + "',");
            strSql.Append("SETTOPTIME='" + FileModel.SETTOPTIME + "',");
            strSql.Append("FILE_TITEL='" + FileModel.FILE_TITEL + "'");
            strSql.Append(" where FILE_ID='" + FileModel.FILE_ID + "' ");
            strArry.Add(strSql);
            #endregion

            #region 修改文件属性
            StringBuilder strSqls = new StringBuilder();
            strSqls.Append("update T_PUB_FILEATTRIBUTE set ");
            if (FileAttribute.AREA != null)
            {
                strSqls.Append("AREA='" + FileAttribute.AREA + "',");
            }
            else
            {
                strSqls.Append("AREA= null ,");
            }
            if (FileAttribute.CELEBRATION_TYPE != null)
            {
                strSqls.Append("CELEBRATION_TYPE='" + FileAttribute.CELEBRATION_TYPE + "',");
            }
            else
            {
                strSqls.Append("CELEBRATION_TYPE= null ,");
            }
            if (FileAttribute.NEWSCHOOL != null)
            {
                strSqls.Append("NEWSCHOOL='" + FileAttribute.NEWSCHOOL + "',");
            }
            else
            {
                strSqls.Append("NEWSCHOOL= null ,");
            }
            if (FileAttribute.MYXILAI != null)
            {
                strSqls.Append("MYXILAI='" + FileAttribute.MYXILAI + "',");
            }
            else
            {
                strSqls.Append("MYXILAI= null ,");
            }
            if (FileAttribute.STYLE != null)
            {
                strSqls.Append("STYLE='" + FileAttribute.STYLE + "',");
            }
            else
            {
                strSqls.Append("STYLE= null ,");
            }
            if (FileAttribute.COLOR != null)
            {
                strSqls.Append("COLOR='" + FileAttribute.COLOR + "',");
            }
            else
            {
                strSqls.Append("COLOR= null ,");
            }
            if (FileAttribute.DRESS_TYPE != null)
            {
                strSqls.Append("DRESS_TYPE='" + FileAttribute.DRESS_TYPE + "',");
            }
            else
            {
                strSqls.Append("DRESS_TYPE= null ,");
            }
            if (FileAttribute.DRESS_LEVEL != null)
            {
                strSqls.Append("DRESS_LEVEL='" + FileAttribute.DRESS_LEVEL + "',");
            }
            else
            {
                strSqls.Append("DRESS_LEVEL= null ,");
            }
            if (FileAttribute.DRESS_COLOR != null)
            {
                strSqls.Append("DRESS_COLOR='" + FileAttribute.DRESS_COLOR + "',");
            }
            else
            {
                strSqls.Append("DRESS_COLOR= null ,");
            }
            if (FileAttribute.DRESS_PRICE != null)
            {
                strSqls.Append("DRESS_PRICE='" + FileAttribute.DRESS_PRICE + "',");
            }
            else
            {
                strSqls.Append("DRESS_PRICE= null ,");
            }
            if (FileAttribute.WEDDING_COLOR != null)
            {
                strSqls.Append("WEDDING_COLOR='" + FileAttribute.WEDDING_COLOR + "',");
            }
            else
            {
                strSqls.Append("WEDDING_COLOR= null ,");
            }
            if (FileAttribute.WEDDING_PRICE != null)
            {
                strSqls.Append("WEDDING_PRICE='" + FileAttribute.WEDDING_PRICE + "',");
            }
            else
            {
                strSqls.Append("WEDDING_PRICE= null ,");
            }
            if (FileAttribute.WEDDING_MONTH != null)
            {
                strSqls.Append("WEDDING_MONTH='" + FileAttribute.WEDDING_MONTH + "',");
            }
            else
            {
                strSqls.Append("WEDDING_MONTH= null ,");
            }
            if (FileAttribute.WEDDING_STYLE != null)
            {
                strSqls.Append("WEDDING_STYLE='" + FileAttribute.WEDDING_STYLE + "',");
            }
            else
            {
                strSqls.Append("WEDDING_STYLE= null ,");
            }
            if (FileAttribute.MATERIAL_STAR != null)
            {
                strSqls.Append("MATERIAL_STAR='" + FileAttribute.MATERIAL_STAR + "',");
            }
            else
            {
                strSqls.Append("MATERIAL_STAR= null ,");
            }
            if (FileAttribute.HOTEL_NAME != null)
            {
                strSqls.Append("HOTEL_NAME='" + FileAttribute.HOTEL_NAME + "',");
            }
            else
            {
                strSqls.Append("HOTEL_NAME= null ,");
            }
            if (FileAttribute.HOTEL_DESK_NUM != null)
            {
                strSqls.Append("HOTEL_DESK_NUM='" + FileAttribute.HOTEL_DESK_NUM + "',");
            }
            else
            {
                strSqls.Append("HOTEL_DESK_NUM= null ,");
            }
            if (FileAttribute.HOTEL_STYLE != null)
            {
                strSqls.Append("HOTEL_STYLE='" + FileAttribute.HOTEL_STYLE + "',");
            }
            else
            {
                strSqls.Append("HOTEL_STYLE= null ,");
            }
            if (FileAttribute.HOTEL_SPECIFICATION != null)
            {
                strSqls.Append("HOTEL_SPECIFICATION='" + FileAttribute.HOTEL_SPECIFICATION + "',");
            }
            else
            {
                strSqls.Append("HOTEL_SPECIFICATION= null ,");
            }
            if (FileAttribute.HOTEL_LOCATION != null)
            {
                strSqls.Append("HOTEL_LOCATION='" + FileAttribute.HOTEL_LOCATION + "',");
            }
            else
            {
                strSqls.Append("HOTEL_LOCATION= null ,");
            }
            if (FileAttribute.MAX_PRICE != null)
            {
                strSqls.Append("MAX_PRICE=" + FileAttribute.MAX_PRICE + ",");
            }
            else
            {
                strSqls.Append("MAX_PRICE= null ,");
            }
            if (FileAttribute.MIN_PRICE != null)
            {
                strSqls.Append("MIN_PRICE=" + FileAttribute.MIN_PRICE + ",");
            }
            else
            {
                strSqls.Append("MIN_PRICE= null ,");
            }
            if (FileAttribute.PROJECT_TYPE != null)
            {
                strSqls.Append("PROJECT_TYPE='" + FileAttribute.PROJECT_TYPE + "',");
            }
            else
            {
                strSqls.Append("PROJECT_TYPE= null ,");
            }
            int n = strSqls.ToString().LastIndexOf(",");
            strSqls.Remove(n, 1);
            strSqls.Append(" where FILE_ID='" + FileAttribute.FILE_ID + "' ");
            strArry.Add(strSqls);
            #endregion

            DBHelper.ExecuteSqlTran(strArry);
        }


        public List<Model.Progect.T_PUB_FILE> GetFileList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.FILE_ID,FILE_NAME,FILE_TITEL,TYPE,URLOriginal,URLThumbnail,URLVideoPhoto,BRANCH_ID,UPTIME,GETTIME,USERID,USERNAME,REAMRK,ISUSED,ISFLAG,FILE_FORM,SETTOPTIME,UPDATEUSERID,UPDATEUSERNAME,PROJECTREAMRK ");
            strSql.Append(" FROM T_PUB_FILE as a,T_PUB_PROJECTFILE as b ");
            strSql.Append(" where a.FILE_ID = b.PROJECT_ID ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(strWhere);
            }
            List<Model.Progect.T_PUB_FILE> list = new List<Model.Progect.T_PUB_FILE>();
            Database db = DatabaseFactory.CreateDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
            }
            return list;
        }

        #region  Method
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Model.Progect.T_PUB_FILE model)
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into T_PUB_FILE(");
                strSql.Append("FILE_ID,FILE_NAME,FILE_TITEL,TYPE,URLOriginal,URLThumbnail,URLVideoPhoto,BRANCH_ID,UPTIME,GETTIME,USERID,USERNAME,REAMRK,ISUSED,ISFLAG,FILE_FORM,SETTOPTIME,UPDATEUSERID,UPDATEUSERNAME,PROJECTREAMRK)");
                strSql.Append(" values (");
                strSql.Append("@FILE_ID,@FILE_NAME,@FILE_TITEL,@TYPE,@URLOriginal,@URLThumbnail,@URLVideoPhoto,@BRANCH_ID,@UPTIME,@GETTIME,@USERID,@USERNAME,@REAMRK,@ISUSED,@ISFLAG,@FILE_FORM,@SETTOPTIME,@UPDATEUSERID,@UPDATEUSERNAME,@PROJECTREAMRK)");
                Database db = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
                db.AddInParameter(dbCommand, "FILE_ID", DbType.String, model.FILE_ID);
                db.AddInParameter(dbCommand, "FILE_NAME", DbType.String, model.FILE_NAME);
                db.AddInParameter(dbCommand, "FILE_TITEL", DbType.String, model.FILE_TITEL);
                db.AddInParameter(dbCommand, "TYPE", DbType.String, model.TYPE);
                db.AddInParameter(dbCommand, "URLOriginal", DbType.String, model.URLOriginal);
                db.AddInParameter(dbCommand, "URLThumbnail", DbType.String, model.URLThumbnail);
                db.AddInParameter(dbCommand, "URLVideoPhoto", DbType.String, model.URLVideoPhoto);
                db.AddInParameter(dbCommand, "BRANCH_ID", DbType.Int32, model.BRANCH_ID);
                db.AddInParameter(dbCommand, "UPTIME", DbType.DateTime, model.UPTIME);
                db.AddInParameter(dbCommand, "GETTIME", DbType.DateTime, model.GETTIME);
                db.AddInParameter(dbCommand, "USERID", DbType.Int32, model.USERID);
                db.AddInParameter(dbCommand, "USERNAME", DbType.String, model.USERNAME);
                db.AddInParameter(dbCommand, "REAMRK", DbType.String, model.REAMRK);
                db.AddInParameter(dbCommand, "ISUSED", DbType.Boolean, model.ISUSED);
                db.AddInParameter(dbCommand, "ISFLAG", DbType.Boolean, model.ISFLAG);
                db.AddInParameter(dbCommand, "FILE_FORM", DbType.String, model.FILE_FORM);
                db.AddInParameter(dbCommand, "SETTOPTIME", DbType.DateTime, model.SETTOPTIME);
                db.AddInParameter(dbCommand, "UPDATEUSERID", DbType.Int32, model.UPDATEUSERID);
                db.AddInParameter(dbCommand, "UPDATEUSERNAME", DbType.String, model.UPDATEUSERNAME);
                db.AddInParameter(dbCommand, "PROJECTREAMRK", DbType.String, model.PROJECTREAMRK);
                db.ExecuteScalar(dbCommand);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);

            }
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string FILE_ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_PUB_FILE set ");
            strSql.Append("ISUSED=0");
            strSql.Append(" where FILE_ID='" + FILE_ID + "'");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            int rows = db.ExecuteNonQuery(dbCommand);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.Progect.T_PUB_FILE model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_PUB_FILE set ");
            strSql.Append("FILE_NAME=@FILE_NAME,");
            strSql.Append("FILE_TITEL=@FILE_TITEL,");
            strSql.Append("TYPE=@TYPE,");
            strSql.Append("URLOriginal=@URLOriginal,");
            strSql.Append("URLThumbnail=@URLThumbnail,");
            strSql.Append("URLVideoPhoto=@URLVideoPhoto,");
            strSql.Append("BRANCH_ID=@BRANCH_ID,");
            strSql.Append("UPTIME=@UPTIME,");
            strSql.Append("GETTIME=@GETTIME,");
            strSql.Append("USERID=@USERID,");
            strSql.Append("USERNAME=@USERNAME,");
            strSql.Append("REAMRK=@REAMRK,");
            strSql.Append("ISUSED=@ISUSED,");
            strSql.Append("ISFLAG=@ISFLAG,");
            strSql.Append("FILE_FORM=@FILE_FORM,");
            strSql.Append("SETTOPTIME=@SETTOPTIME,");
            strSql.Append("UPDATEUSERID=@UPDATEUSERID,");
            strSql.Append("UPDATEUSERNAME=@UPDATEUSERNAME,");
            strSql.Append("PROJECTREAMRK=@PROJECTREAMRK");
            strSql.Append(" where FILE_ID=@FILE_ID ");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "FILE_ID", DbType.String, model.FILE_ID);
            db.AddInParameter(dbCommand, "FILE_NAME", DbType.String, model.FILE_NAME);
            db.AddInParameter(dbCommand, "FILE_TITEL", DbType.String, model.FILE_TITEL);
            db.AddInParameter(dbCommand, "TYPE", DbType.String, model.TYPE);
            db.AddInParameter(dbCommand, "URLOriginal", DbType.String, model.URLOriginal);
            db.AddInParameter(dbCommand, "URLThumbnail", DbType.String, model.URLThumbnail);
            db.AddInParameter(dbCommand, "URLVideoPhoto", DbType.String, model.URLVideoPhoto);
            db.AddInParameter(dbCommand, "BRANCH_ID", DbType.Int32, model.BRANCH_ID);
            db.AddInParameter(dbCommand, "UPTIME", DbType.DateTime, model.UPTIME);
            db.AddInParameter(dbCommand, "GETTIME", DbType.DateTime, model.GETTIME);
            db.AddInParameter(dbCommand, "USERID", DbType.Int32, model.USERID);
            db.AddInParameter(dbCommand, "USERNAME", DbType.String, model.USERNAME);
            db.AddInParameter(dbCommand, "REAMRK", DbType.String, model.REAMRK);
            db.AddInParameter(dbCommand, "ISUSED", DbType.Boolean, model.ISUSED);
            db.AddInParameter(dbCommand, "ISFLAG", DbType.Boolean, model.ISFLAG);
            db.AddInParameter(dbCommand, "FILE_FORM", DbType.String, model.FILE_FORM);
            db.AddInParameter(dbCommand, "SETTOPTIME", DbType.DateTime, model.SETTOPTIME);
            db.AddInParameter(dbCommand, "UPDATEUSERID", DbType.Int32, model.UPDATEUSERID);
            db.AddInParameter(dbCommand, "UPDATEUSERNAME", DbType.String, model.UPDATEUSERNAME);
            db.AddInParameter(dbCommand, "PROJECTREAMRK", DbType.String, model.PROJECTREAMRK);
            int rows = db.ExecuteNonQuery(dbCommand);

            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Progect.T_PUB_FILE GetModel(string FILE_ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FILE_ID,FILE_NAME,FILE_TITEL,TYPE,URLOriginal,URLThumbnail,URLVideoPhoto,BRANCH_ID,UPTIME,GETTIME,USERID,USERNAME,REAMRK,ISUSED,ISFLAG,FILE_FORM,SETTOPTIME,UPDATEUSERID,UPDATEUSERNAME,PROJECTREAMRK from T_PUB_FILE ");
            strSql.Append(" where FILE_ID=@FILE_ID ");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "FILE_ID", DbType.String, FILE_ID);
            Model.Progect.T_PUB_FILE model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT FILE_ID,TYPE,FILE_NAME,FILE_TITEL,UPTIME,USERNAME,ISFLAG,BRANCH_NAME,PROJECTREAMRK,URLThumbnail,URLOriginal,URLVideoPhoto ");
            strSql.Append("  FROM T_PUB_FILE as A,T_PUB_BRANCH as B ");
            strSql.Append("WHERE A.BRANCH_ID=B.BRANCH_ID");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" and " + strWhere + "order by SETTOPTIME desc, UPTIME desc");
            }
            Database db = DatabaseFactory.CreateDatabase();
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public List<Model.Progect.T_PUB_FILE> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FILE_ID,FILE_NAME,FILE_TITEL,TYPE,URLOriginal,URLThumbnail,URLVideoPhoto,BRANCH_ID,UPTIME,GETTIME,USERID,USERNAME,REAMRK,ISUSED,ISFLAG,FILE_FORM,SETTOPTIME,UPDATEUSERID,UPDATEUSERNAME,PROJECTREAMRK ");
            strSql.Append(" FROM T_PUB_FILE ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere + "order by SETTOPTIME desc, UPTIME desc");
            }
            List<Model.Progect.T_PUB_FILE> list = new List<Model.Progect.T_PUB_FILE>();
            Database db = DatabaseFactory.CreateDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
            }
            return list;
        }


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public Model.Progect.T_PUB_FILE ReaderBind(IDataReader dataReader)
        {
            Model.Progect.T_PUB_FILE model = new Model.Progect.T_PUB_FILE();
            object ojb;
            model.FILE_ID = dataReader["FILE_ID"].ToString();
            model.FILE_NAME = dataReader["FILE_NAME"].ToString();
            model.FILE_TITEL = dataReader["FILE_TITEL"].ToString();
            model.TYPE = dataReader["TYPE"].ToString();
            model.URLOriginal = dataReader["URLOriginal"].ToString();
            model.URLThumbnail = dataReader["URLThumbnail"].ToString();
            model.URLVideoPhoto = dataReader["URLVideoPhoto"].ToString();
            ojb = dataReader["BRANCH_ID"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BRANCH_ID = (int)ojb;
            }
            ojb = dataReader["UPTIME"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UPTIME = (DateTime)ojb;
            }
            ojb = dataReader["GETTIME"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.GETTIME = (DateTime)ojb;
            }
            ojb = dataReader["USERID"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.USERID = (int)ojb;
            }
            model.USERNAME = dataReader["USERNAME"].ToString();
            model.REAMRK = dataReader["REAMRK"].ToString();
            ojb = dataReader["ISUSED"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ISUSED = (bool)ojb;
            }
            ojb = dataReader["ISFLAG"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ISFLAG = (bool)ojb;
            }
            model.FILE_FORM = dataReader["FILE_FORM"].ToString();
            ojb = dataReader["SETTOPTIME"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.SETTOPTIME = (DateTime)ojb;
            }
            ojb = dataReader["UPDATEUSERID"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UPDATEUSERID = (int)ojb;
            }
            model.UPDATEUSERNAME = dataReader["UPDATEUSERNAME"].ToString();
            model.PROJECTREAMRK = dataReader["PROJECTREAMRK"].ToString();
            return model;
        }

        #endregion  Method
    }
}